﻿@model mesoBoard.Framework.Models.PostRow
    @{
       string postClass;
       if (Model.Thread.FirstPost.PostID == Model.Post.PostID)
       {
           postClass = "first";
       }
       else if (Model.IsLastPost)
       {
           postClass = "last";
       }
       else
       {
           postClass = Model.IsOdd ? "bg_color2" : "bg_color3";
       }
    }
    
    <a id="@Model.Post.PostID "></a> 
    <div class="post_row @postClass ">

        <div class="user">
        
            @if(!string.IsNullOrEmpty(Model.Post.User.UserProfile.Avatar)){    
            <div class="avatar">
                @Html.UserAvatar(Model.Post.UserID) 
            </div>
            } 
        
            <div class="username">
                @Html.UsernameLink(Model.Post.User) 
            </div>
            
            <div class="rank">
                @Html.UserRank(Model.Post.User) 
            </div>
            
            <ul class="info">
                <li>
                    @Html.ActionLink("Private Message", "SendMessage", "Messages", new { ToUserName = Model.Post.User.Username }, "") 
                </li>
                <li>
                    @Model.Post.User.Posts.Count  posts
                </li>
                <li>
                    Joined: @Model.Post.User.RegisterDate.ToString("MMM yyyy") 
                </li>

                @if(string.IsNullOrWhiteSpace(Model.Post.User.UserProfile.Location)){ 
                <li>
                    Location: @Model.Post.User.UserProfile.Location 
                </li>
                 } 
            </ul>
        </div>
        
        <div class="body">
            <div class="top">
                <div class="date">
                    by <b>@Html.UserProfileLink(Model.Post.User.Username) </b> on <b>@Model.Post.Date.ToString("ddd, MMM dd \\'yy h:mm tt") </b>
                </div>
                                
                <div class="actions">
                    <ul>
                        @if(Model.IsAuthenticated) 
                        { 
                        
                            if(Model.CanPost){ 
                                <li>@Html.ActionLink("quote", "CreatePost", "Post", new { ThreadID = Model.Post.ThreadID, QuotePostID = Model.Post.PostID }, new { @class = "quote_post link_button" })</li>
                            } 
                    
                            if(Model.CanEdit){ 
                                <li>@Html.ActionLink("edit", "EditPost", "Post", new { PostID = Model.Post.PostID }, new { @class = "edit_post link_button" })</li>
                            } 
                    
                            <li>@Html.ActionLink("report", "ReportPost", "Post", new { PostID = Model.Post.PostID }, new { @class = "report_post link_button" })</li>
                      
                            if(Model.CanDelete){ 
                                <li>@Html.ConfirmLink("delete", Url.Action("DeletePost", "Post", new { PostID = Model.Post.PostID }), Url.Action("ViewThread", "Board", new { threadID = Model.Thread.ThreadID }), new { @class = "delete_post link_button" })</li>
                            } 
                        
                         } 
                        <li><a class="link_post link_button" href="@Url.Action("ViewThread", "Board", new { ThreadID = Model.Thread.ThreadID, PostID = Model.Post.PostID})#@(Model.Post.PostID)">link</a></li>
                    </ul>
                </div>
            </div>
            
            <hr />                      
                            
            <div class="text">
                @Html.Raw(Model.Post.ParsedText)
            </div>

            @if(Model.Post.Attachments.Count > 0){ 
                <div class="attachments">
                    @foreach(var attachment in Model.Post.Attachments){ 
                        <table>
                            <tr>
                                <th>@Html.FileTypeImage(System.IO.Path.GetExtension(attachment.DownloadName)) @attachment.DownloadName.Shorten(25)</th>
                            </tr>
                            <tr>
                                <td>Size: @Html.FriendlyFileSize(attachment.Size)</td>
                            </tr>
                            <tr>
                                <td>Downloaded: @attachment.Downloaded times</td>
                            </tr>
                            <tr>
                                <th>
                                    @Html.ActionLink("Download", "DownloadAttachment", "Board", new { AttachmentID = attachment.AttachmentID}, "")
                                </th>
                            </tr>
                        </table>
                    } 
                </div>
            } 

            @if (!string.IsNullOrWhiteSpace(Model.Post.User.UserProfile.ParsedSignature))
            {
                if (Model.Post.UseSignature || Model.Post.User.UserProfile.AlwaysShowSignature){ 
                    <hr />
                    <div class="signature">
                        @Html.Raw(Model.Post.User.UserProfile.ParsedSignature)
                    </div>
                }
            }
        </div>
    </div>
